#include <iostream>
#include <fstream>
#include <ctime>

using namespace std;
int numbers[5000];
void bubbleSort(int arr[]) {
	for (size_t i = 0; i < 4999; i++)
	{
		bool sorted = true;
		for (size_t j = 0; j < 4999-i; j++)
		{
			if (arr[j] > arr[j + 1]) {
				sorted = false;
				int nastya = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = nastya;
			}
		}
		if (sorted) return;
	}
}
void readFile(string fileName) {
	ifstream file(fileName);
	if (file.is_open())
	{
		int n;

		for (size_t i = 0; i < 5000; i++)
		{
			file >> numbers[i];
		}
		clock_t d = clock();
		bubbleSort(numbers);
		clock_t end = clock();
		cout << fileName.substr(0, fileName.find('.')) <<
			" " << end - d << " milliseconds" << endl;

	}
	else {
		cout << "Fail open: "<< fileName;
	}
	file.close();
}

int main() {
	readFile("m1_sorted.txt");
	readFile("m2_reverse.txt");
	readFile("m3_shuffle.txt");
}
